package com.tanhua.server.Controller;

import com.tanhua.model.vo.PageResult;
import com.tanhua.server.service.MessagesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/messages")
public class MessagesController {

    @Autowired
    private MessagesService messagesService;

    //联系人添加
    @PostMapping("/contacts")
    public ResponseEntity contacts(@RequestBody Map map) {
        //1. 获取参数
        String str = map.get("userId").toString();
        Long friendId = Long.valueOf(str);//好友id
        //2. 调用service方法
        messagesService.contacts(friendId);
        return ResponseEntity.ok(null);
    }

    //联系人列表
    @GetMapping("/contacts")
    public ResponseEntity contacts(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer pagesize) {
        PageResult vo = messagesService.findFriends(page, pagesize);
        return ResponseEntity.ok(vo);
    }
}
